#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=110*110;
int n,m,head[110],cnt,match[110],a[110][110],mx1[110],mx2[110];
LL ans;
bool vis[110];
struct edge
{
	int v,next;
}e[MAXN];
void addedge(int x,int y)
{
	e[++cnt]=(edge){y,head[x]};
	head[x]=cnt;
	return;
}
bool Hungary(int u)
{
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		if(!vis[v])
		{
			vis[v]=true;
			if(!match[v]||Hungary(match[v]))
			{
				match[v]=u;
				return true;
			}
		}
	}
	return false;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();m=read();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			a[i][j]=read();
			mx1[i]=max(mx1[i],a[i][j]);
			mx2[j]=max(mx2[j],a[i][j]);
			if(a[i][j])ans+=a[i][j]-1;
		}
	for(int i=1;i<=n;++i)if(mx1[i])ans-=mx1[i]-1;
	for(int i=1;i<=m;++i)if(mx2[i])ans-=mx2[i]-1;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(mx1[i]==mx2[j]&&a[i][j])
				addedge(i,j);
	for(int i=1;i<=n;++i)
	{
		memset(vis,0,sizeof(vis));
		if(Hungary(i))ans+=mx1[i]-1;
	}
	printf("%lld\n",ans);
	return 0;
}
